package com.welink.cmp.dao.metadata;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.welink.cmp.dao.metadata.dataobject.SwitchDO;
import com.welink.cmp.dto.metadata.switchs.query.SwitchListByPageQry;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yanwei li create  2024-05-20 21:23
 */

@Component
public class SwitchDaoService extends ServiceImpl<SwitchMapper, SwitchDO> {


    public List<SwitchDO> getListByName(List<String> names){
        LambdaQueryWrapper<SwitchDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(SwitchDO::getName,names);
        final List<SwitchDO> list = this.list(wrapper);
        return list;
    }

    /**
     * 分页查询交换机信息
     *
     * @param pageQry 分页查询参数，包括分页信息和查询条件
     * @return 分页结果，包括交换机列表和分页信息
     */
    public Page<SwitchDO> pageQry(SwitchListByPageQry pageQry) {
        Page<SwitchDO> page = new Page<>(pageQry.getPageIndex(), pageQry.getPageSize());
        LambdaQueryWrapper<SwitchDO> wrapper = new LambdaQueryWrapper<>();
        if (pageQry.getName() != null) {
            wrapper.eq(SwitchDO::getName, pageQry.getName());
        }
        if (pageQry.getStrCreateTime() != null) {
            wrapper.ge(SwitchDO::getCreateTime, pageQry.getStrCreateTime());
        }
        if (pageQry.getEndCreateTime() != null) {
            wrapper.le(SwitchDO::getCreateTime, pageQry.getEndCreateTime());
        }
        return this.page(page, wrapper);
    }


}
